Skip to content

Add integrity checks during package upload#71

Merged
bradhe merged 5 commits intodevelopfrom
tasks/add-integrity-checks-to-deployments
Jul 24, 2025
Merged

Add integrity checks during package upload#71
bradhe merged 5 commits intodevelopfrom
tasks/add-integrity-checks-to-deployments

Conversation

@bradhe
Copy link
Contributor

@bradhe bradhe commented Jul 22, 2025

This PR introduces calculating package content integrity checks, as well as overall package integrity checks that are sent to the server. This allows us to figure out what's going on with clients on the server, and return better error messages about potential corruption.

@bradhe bradhe requested review from Copilot and socksy July 22, 2025 15:49

This comment was marked as outdated.

@bradhe bradhe requested review from Copilot and konstantinoscs July 23, 2025 15:51

This comment was marked as outdated.

@tower tower deleted a comment from Copilot AI Jul 23, 2025
@bradhe bradhe requested a review from Copilot July 23, 2025 19:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces integrity checking for package uploads by implementing SHA256 checksums for both individual files and overall package content. The changes enable better error detection and debugging by allowing the server to verify package integrity and identify potential corruption issues.

  • Adds SHA256 checksum calculation for individual files within packages
  • Implements overall package integrity verification by hashing all file checksums
  • Includes checksum metadata in package manifests and upload headers

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/tower-package/Cargo.toml Adds sha2 dependency for cryptographic hashing
crates/tower-package/src/lib.rs Implements core checksum functionality and adds checksum field to manifest
crates/tower-package/tests/package_test.rs Adds test assertion to verify checksum is populated in manifest
crates/tower-cmd/src/util/deploy.rs Computes package checksum and includes it in upload request header
crates/tower-cmd/src/util/progress.rs Minor formatting changes with whitespace additions
Comments suppressed due to low confidence (1)

crates/tower-package/tests/package_test.rs:204

  • The test only checks that a checksum exists but doesn't verify its correctness or format. Consider adding a test that validates the checksum is a valid SHA256 hex string (64 characters, hexadecimal).
    assert!(!manifest.checksum.is_empty(), "Manifest integrity check was not set");


for key in sorted_keys {
// We need to sort the keys so that we can compute a consistent hash.
let value = path_hashes.get(key).unwrap();
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using unwrap() is unsafe here. Since we're iterating over keys from the same HashMap, this should never fail, but it's better to handle the error case properly or use a more explicit approach like path_hashes[key].

Suggested change
let value = path_hashes.get(key).unwrap();
let value = path_hashes.get(key).expect("Key not found in path_hashes");

Copilot uses AI. Check for mistakes.
Ok(format!("{:x}", result))
}

pub async fn compute_sha256_file(file_path: &PathBuf) -> Result<String, Error> {
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This function is marked as pub but appears to be an internal utility. Consider making it private or moving it to a separate module if it needs to be shared between crates.

Suggested change
pub async fn compute_sha256_file(file_path: &PathBuf) -> Result<String, Error> {
async fn compute_sha256_file(file_path: &PathBuf) -> Result<String, Error> {

Copilot uses AI. Check for mistakes.
Ok(hash) => hash,
Err(e) => {
debug!("Failed to compute package hash: {}", e);
output::die("Tower CLI failed to properly prepare your package for deployment. Check that you have permissions to read/write to your temporary directory, and if it keeps happening contact Tower support at https://tower.dev");
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message is generic and doesn't mention the specific failure (checksum computation). Consider making it more specific: 'Tower CLI failed to compute package checksum during deployment preparation.'

Suggested change
output::die("Tower CLI failed to properly prepare your package for deployment. Check that you have permissions to read/write to your temporary directory, and if it keeps happening contact Tower support at https://tower.dev");
output::die("Tower CLI failed to compute package checksum during deployment preparation. Check that you have permissions to read/write to your temporary directory, and if it keeps happening contact Tower support at https://tower.dev");

Copilot uses AI. Check for mistakes.
}

fn compute_sha256_package(path_hashes: &HashMap<PathBuf, String>) -> Result<String, Error> {
let mut sorted_keys: Vec<&PathBuf> = path_hashes.keys().collect();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe dumb question, but it seems we're passing in a full (relative?) path, whereas in the go code we're hashing the filename — are these the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think their cooincidentally the same. I need to do more research. This is especially interesting in the case of e.g. Windows. Let's ship this, and I'll follow up with a bug fix accordingly.

Copy link
Contributor

@socksy socksy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than filepath question, looks good 👍

@bradhe bradhe merged commit c73b887 into develop Jul 24, 2025
4 checks passed
@bradhe bradhe deleted the tasks/add-integrity-checks-to-deployments branch July 24, 2025 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants